package com.cincc.cinccimdemo.viewholder;

import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.adapter.ConversationAdapter;
import com.cincc.cinccimdemo.common.EmojiUtils;
import com.cincc.cinccimdemo.model.MessageInfoUI;
import com.cincc.im.model.enums.ImSendType;
import com.cincc.im.model.message.ImTextMessage;

public class ReceiveTextViewHolder extends MessageContentHolder {
    public ImageView iv_face;
    public TextView tv_message;
    public TextView tv_username;
    public TextView tv_time;
    public TextView ref_text;

    public ReceiveTextViewHolder(Context context, View itemView, ConversationAdapter adapter) {
        super(context, itemView, adapter);
        iv_face = itemView.findViewById(R.id.iv_face);
        tv_message = itemView.findViewById(R.id.tv_message);
        tv_username = itemView.findViewById(R.id.username_text);
        tv_time = itemView.findViewById(R.id.tv_time);
        ref_text = itemView.findViewById(R.id.refTextView);
    }

    @Override
    public void bindView(MessageInfoUI uiMessage, int position) {
        super.bindView(uiMessage, position);
        ImTextMessage imTextMessage = (ImTextMessage) uiMessage.getMessageInfo().imMessage;
        SpannableString spannableString = EmojiUtils.text2Emoji(context,
                imTextMessage.msgContent, tv_message.getTextSize());
        tv_message.setText(spannableString);
        tv_username.setText(uiMessage.getMessageInfo().senderName);
        tv_username.setVisibility(ImSendType.isP2P(uiMessage.getMessageInfo().imSendType) ? View.GONE : View.VISIBLE);
        ref_text.setVisibility(TextUtils.isEmpty(imTextMessage.quoteId) ? View.GONE : View.VISIBLE);
        if (!TextUtils.isEmpty(imTextMessage.quoteId)) {
            ref_text.setText(imTextMessage.quoteContent);
        }
    }
}
